﻿import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { sendMsg } from '../actions';
import './buttons.css';

class SendButtonUI extends Component {
    static propTypes = {
        disabled: PropTypes.bool.isRequired,
        send: PropTypes.func.isRequired
    }
    render() {
        return (
            <div className='btn-container'>
                <button
                    disabled={this.props.disabled}
                    className='btn btn-primary'
                    onClick={()=>this.props.send()}>发 送</button>
            </div>
        )
    }
}
const mapState2Props = state => {
    var { candidates = null, msg = null } = state.send;
    return {  disabled: !candidates || !msg }
};
const mapAction2Props = dispatch => ({
    send: () => dispatch(sendMsg())
});
export default connect(mapState2Props, mapAction2Props)(SendButtonUI);